<?php
namespace app\admin\controller;

use app\admin\tool\Parser;
use app\common\model\Admin as AdminModel;
use think\Request;
use think\Loader;
use app\common\model\Role as RoleModel;

/**
 * 个人账号管理
 * Class Account
 * @package app\admin\controller
 */
class Account extends Base
{

    //更新
    public function edit(){
        $this->data['title'] = '密码修改';
        $this->data['model'] = $this->admin;
        return view('',$this->data);
    }

    /**
     * @param Request $request
     */
    public function update(Request $request){
        $data = $request->post();

        $data['id'] = $this->admin->id;

        if(empty($data['password']) || strlen($data['password']) < 6){
            $this->error("请填写密码，至少6位以上");
        }

        $data['password'] = AdminModel::encrypt($data['password']);
        $data['update_time'] = time();

        $navigationModel = new AdminModel();
        if($navigationModel -> save($data,['id'=>$data['id']])){
            $this->success("更新成功");
        }

        $this->error("操作失败");
    }
}